<template>
  <div id="windowTopSearch">
    <div class="search-box">
      <el-form
        ref="searchForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        @submit.native.prevent
      >
        <el-form-item label="状态" prop="status">
          <el-select v-model="formInline.status" clearable placeholder="全部">
            <el-option
              v-for="item in statusList"
              :key="item.value"
              :label="item.key"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="操作人" prop="updateUser">
          <el-select
            v-model="formInline.updateUser"
            clearable
            filterable
            placeholder="全部"
          >
            <el-option
              v-for="item in updateUser"
              :key="item.userId"
              :label="item.trueName"
              :value="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="操作时间" prop="updateTime">
          <el-date-picker
            v-model="formInline.updateTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="checkedUpdateTime"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="直播间频道号" prop="channelId">
          <el-input
            size="small"
            v-model="formInline.channelId"
            maxlength="9"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { getUsers } from '@/api/notice'
export default {
  data() {
    return {
      formInline: {
        status: undefined, //状态
        updateUser: undefined, //操作人
        channelId: undefined, //频道号
        startTime: undefined, //开始时间
        endTime: undefined, //结束时间
        updateTime: []
      },
      statusList: [
        { key: '开启', value: 'OPEN' },
        { key: '关闭', value: 'CLOSE' }
      ],
      updateUser: []
    }
  },
  mounted() {
    //创建人
    let roles = [
      { id: '311' },
      { id: '301' },
      { id: '296' },
      { id: '292' },
      { id: '236' },
      { id: '257' }
    ]
    getUsers(roles, (response) => {
      this.updateUser = response
    })
  },
  methods: {
    // 选择操作时间
    checkedUpdateTime(val) {
      this.formInline.startTime = val && val.length > 1 ? val[0] : ''
      this.formInline.endTime = val && val.length > 1 ? val[1] : ''
    },
    // 搜索
    toSearch() {
      const obj = Object.assign({}, this.formInline)
      delete obj.updateTime
      this.$emit('toSearch', obj)
    },
    // 重置
    reset() {
      this.$refs['searchForm'].resetFields()
      this.checkedUpdateTime([undefined, undefined])
    }
  }
}
</script>
<style lang="less"></style>
